﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace GoldDigger.Models
{
    public class AssociationRuleModel
    {
        public ItemsetModel Lhs { get; set; }
        public ItemsetModel Rhs { get; set; }
        public string LeftHandList { get; set; }
        public string RightHandList { get; set; }
        public double Confidence { get; set; }

        public AssociationRuleModel(ItemsetModel lhs, ItemsetModel rhs, double conf)
        {
            Lhs = lhs;
            Rhs = rhs;
            Confidence = Math.Round(conf,2);
            LeftHandList = GenerateString(lhs);
            RightHandList = GenerateString(rhs);
        }

        public string GenerateString(ItemsetModel im)
        {
            var tmpString = "";
            var count = 1;
            foreach (string s in im.ItemList)
            {
                if (im.ItemList.Count > 1 && count != im.ItemList.Count)
                    tmpString += s + " AND ";
                else
                    tmpString += s;

                count++;
            }

            return tmpString;
        }
    }
}
